public class UniquePaths {

    public int uniquePaths(int m, int n) {
        int[][] dp = new int[m][n];
        for (int i = 0; i < m; i++) {
            dp[i][n - 1] = 1;
        }
        for (int i = m - 1; i >= 0; i--) {
            for (int j = n - 2; j >= 0; j--) {
                dp[i][j] = value(i, j + 1, dp, m, n) + value(i + 1, j, dp, m, n);
            }
        }
        return dp[0][0];
    }
    public int value(int i, int j, int[][] dp,int m,int n) {
        if (i < 0 || i > m - 1 || j < 0 || j > n - 1) return 0;
        return dp[i][j];
    }
}
